package com.leetcode.August;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 17. 电话号码的字母组合
 * @Author: Mr.Fxy
 * @CreateTime: 2024-08-11 22:11
 */
public class LC17电话号码的字母组合 {
    //    private final List<String> ans = new ArrayList<>();
//    private char[] digits, path;
//    String[] numString = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
//
//
//    public List<String> letterCombinations(String digits) {
//        int n = digits.length();
//        if (n == 0) return List.of();
//        this.digits = digits.toCharArray();
//        path = new char[n];
//        dfs(0);
//        return ans;
//    }
//
//    private void dfs(int index) {
//        if (index == digits.length) {
//            ans.add(new String(path));
//            return;
//        }
//        for (char c : numString[digits[index] - '0'].toCharArray()) {
//            path[index] = c;
//            dfs(index + 1);
//        }
//    }
    private final List<String> ans = new ArrayList<>();
    private char[] digits, path;
    String[] numString = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    public List<String> letterCombinations(String digits) {
        int n = digits.length();
        if (n == 0) return List.of();
        this.digits = digits.toCharArray();
        path = new char[n];
        dfs(0);
        return ans;
    }
    private void dfs(int index) {
        if (index == digits.length){
            ans.add(new String(path));
            return;
        }
        for (char c : numString[digits[index]-'0'].toCharArray()) {
            path[index]=c;
            dfs(index+1);
        }
    }
}
